package com.xxx;

import java.io.DataInputStream;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerB extends Thread{
    @Override
    public void run() {
        System.out.println("服务器B启动");


        try {
            ServerSocket serverB = new ServerSocket(8888);

            Socket accept = serverB.accept();

            InputStream is = accept.getInputStream();
            DataInputStream dis = new DataInputStream(is);
            System.out.println(accept.getRemoteSocketAddress() + "上线了");
            System.out.println(accept.getPort());
            while (true) {
                try {
                    String s = dis.readUTF();
                    System.out.println(s);
                } catch (Exception e) {
                    System.out.println(accept.getRemoteSocketAddress() + "离线了");
                    serverB.close();
                    break;
                }

            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
